using System;
using NUnit.Framework;
using PhillyCodeCamp.Domain;
using PhillyCodeCamp.DTO;
using PhillyCodeCamp.Mappers;
using PhillyCodeCamp.Services;
using PhillyCodeCampSpecs.Helpers;

namespace PhillyCodeCampSpecs.Mapper
{
    [TestFixture]
    public class when_mapping_from_from_a_tax_data_dto
    {
        [Test]
        public void should_create_a_tax_return_object ()
        {
            var taxDataDTO = new TaxDataDTO ("01/02/1990", "abc", "555", true);

            var systemUnderTest = new TaxReturnMapper(ObjectMother.CreateTaxRateService(0, 0));

            ITaxRateService stubTaxRateService = ObjectMother.CreateTaxRateService(0M, 0M);
            ITaxReturn expectedTaxReturn = new TaxReturn(555, "abc", new DateTime(1990, 1, 2), true, stubTaxRateService);
            ITaxReturn actualTaxReturn = systemUnderTest.MapTaxReturn(taxDataDTO);

            Assert.IsTrue(actualTaxReturn.IsEqualTo (expectedTaxReturn));
        }
    }

    public static class TaxReturnExtensions
    {
        public static bool IsEqualTo (this ITaxReturn actual, ITaxReturn expected)
        {
            var actualTaxReturn = (TaxReturn) actual;
            var expectedTaxReturn = (TaxReturn) expected;

            return (actualTaxReturn.Income == expectedTaxReturn.Income &&
                    actualTaxReturn.SubmissionDate == expectedTaxReturn.SubmissionDate &&
                    actualTaxReturn.IsBailedOut == expectedTaxReturn.IsBailedOut &&
                    actualTaxReturn.UsState == expectedTaxReturn.UsState);
        }
    }
}